<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="container-fluid px-0">
<div class="row">
	<div class="col-12">
		<div class="btn-group mb-3" role="group">
			<?php echo admin_tab_active($menu['plugin']['tab'], $tab);?>
		</div>

		<div class="card">
			<div class="card-body">
				<div class="media">
					<div>
						<img src="<?php echo $plugin['icon_url']; ?>" width="54" height="54" class="mr-3" />
					</div>
					<div class="media-body">
						<h4>
                            <?php echo $plugin['name']; ?> v<?php echo $plugin['version']; ?>
                        </h4>
						<p>
                            <?php echo $plugin['brief']; ?>
                        </p>
					</div>
				</div>
				<hr />
				<div class="row line-height-3">
					<div class="col-md-6">
						<span class="text-muted"><?php echo lang('plugin_dir');?></span>：
						<?php echo $dir; ?>
					</div>

					<div class="col-md-6">
						<span class="text-muted"><?php echo lang('plugin_version');?></span>：
						<?php echo $plugin['software_version']; ?>
					</div>

					<?php if(!empty($plugin['storeid'])) { ?>
					<div class="col-md-6">
						<span class="text-muted"><?php echo lang('price');?></span>：
						<span class="price"><?php echo $plugin['official']['price']; ?>元</span>
					</div>

					<div class="col-md-6">
						<span class="text-muted"><?php echo lang('installs');?></span>：
						<span><?php echo $plugin['installs']; ?></span>
					</div>

					<div class="col-md-6">
						<span class="text-muted"><?php echo lang('plugin_sells');?></span>：
						<span><?php echo $plugin['sells']; ?></span>
					</div>

					<div class="col-md-6">
						<span class="text-muted"><?php echo lang('plugin_is_cert');?></span>：
						<span><?php echo $plugin['is_cert_fmt']; ?></span>
					</div>

					<div class="col-md-6">
						<span class="text-muted"><?php echo lang('plugin_brief_url');?></span>：
						<span><a href="<?php echo $plugin['brief_url']; ?>" target="_blank"><?php echo $plugin['brief_url']; ?></a></span>
					</div>

					<div class="col-md-6">
						<span class="text-muted">客服QQ</span>：
						<span class="font-weight-bold text-danger"><?php echo $plugin['qq']; ?></span>
					</div>

					<?php  } ?>
				</div>
				<hr />
				<!-- $verify_token === FALSE 登录-->
                <?php if($verify_token === FALSE) { ?>
                <div class="col-md-4 mx-auto">
                    <p class="text-danger">
                        输入 WellCMS 官方登录账户和密码，登录后方可支付和下载
                    </p>
                    <div class="ajax_modal_body">
                        <form action="<?php echo url('plugin-read');?>" method="post" id="form">
                            <div class="form-group input-group">
                                <div class="input-group-prepend">
                                    <span class="input-group-text"><i class="icon icon-user icon-fw"></i></span>
                                </div>
                                <input type="text" class="form-control" placeholder="<?php echo lang('email');?> / <?php echo lang('username');?>" id="email" name="email">
                                <div class="invalid-feedback"></div>
                            </div>
                            <div class="form-group input-group">
                                <div class="input-group-prepend">
                                    <span class="input-group-text"><i class="icon icon-lock icon-fw"></i></span>
                                </div>
                                <input type="password" class="form-control" placeholder="<?php echo lang('password');?>" id="password" name="password">
                                <div class="invalid-feedback"></div>
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>...">
                                    <?php echo lang('login');?>
                                </button>
                            </div>
                            <div class="media">
                                <div class="media-body text-right">
                                    <a target="_blank" href="http://www.wellcms.cn/" class="text-muted">
                                        <small>
                                            <?php echo lang('user_create');?>
                                        </small>
                                    </a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <?php }else{ ?>
                <p class="mt-3 text-center text-danger">
                    本地模式禁止支付、下载付费的插件和主题风格
                </p>
                <?php } ?>

				<?php if($errmsg) { ?>
				<div class="alert alert-primary">
					<?php echo $errmsg; ?>
				</div>
				<?php } ?>

				<?php if(!empty($plugin['storeid']) && !empty($url)) { ?>
				<div class="row">
					<table width="60%" align="center">
						<tr>
							<td><?php if($plugin['img1_url']) { ?> <a href="<?php echo $plugin['img1_url'];?>" target="_blank"><img src="<?php echo $plugin['img1_url'];?>" width="100" height="120" class="border" /></a> <?php } ?></td>
							<td><?php if($plugin['img2_url']) { ?> <a href="<?php echo $plugin['img2_url'];?>" target="_blank"><img src="<?php echo $plugin['img2_url'];?>" width="100" height="120" class="border" /></a> <?php } ?></td>
							<td><?php if($plugin['img3_url']) { ?> <a href="<?php echo $plugin['img3_url'];?>" target="_blank"><img src="<?php echo $plugin['img3_url'];?>" width="100" height="120" class="border" /></a> <?php } ?></td>
							<td><?php if($plugin['img4_url']) { ?> <a href="<?php echo $plugin['img4_url'];?>" target="_blank"><img src="<?php echo $plugin['img4_url'];?>" width="100" height="120" class="border" /></a> <?php } ?></td>
						</tr>
					</table>
				</div>
				<hr />
				<div class="row">
					<div class="col-12" style="text-align: center;">
						<div id="qrcode"></div>
						<br>
						<?php echo lang('plugin_wechat_qrcode_pay');?>
						<br>
						<span class="price">
							<?php echo $plugin['official']['price']; ?>元
						</span>
					</div>
				</div>
				<?php } ?>

				<p class="text-center">
					<?php if($download_url && !$islocal) { ?>
						<a role="button" class="btn btn-primary download" href="<?php echo $download_url; ?>"><?php echo lang('download');?></a>
					<?php } ?>

					<?php if($plugin['setting_url']) { ?>
					<a role="button" class="btn btn-primary setting" href="<?php echo url("plugin-setting-$dir"); ?>"><?php echo lang('setting');?></a>
					<?php } ?>

					<?php if($islocal && !$plugin['installed'] && $plugin['type'] != 1) { ?>
					<a role="button" class="btn btn-primary install" href="<?php echo url("plugin-install-$dir"); ?>"><?php echo lang('install');?></a>
					<?php } ?>

					<?php if($plugin['installed'] && $plugin['enable'] && $plugin['type'] != 1) { ?>
					<a role="button" class="btn btn-secondary disable" href="<?php echo url("plugin-disable-$dir"); ?>"><?php echo lang('disable');?></a>
					<?php } ?>

					<?php if($plugin['installed'] && !$plugin['enable'] && $plugin['type'] != 1) { ?>
					<a role="button" class="btn btn-secondary enable" href="<?php echo url("plugin-enable-$dir"); ?>"><?php echo lang('enable');?></a>
					<?php } ?>

					<?php if($plugin['installed'] && $plugin['type'] != 1) { ?>
					<a role="button" class="btn btn-danger uninstall confirm" data-confirm-text="<?php echo lang('plugin_uninstall_confirm_tips', array('name'=>$plugin['name']));?>" href="<?php echo url("plugin-uninstall-$dir"); ?>"><?php echo lang('uninstall');?></a>
					<?php } ?>

                    <?php if($islocal && !$plugin['installed'] && $plugin['type'] == 1) { ?>
                    <a role="button" class="btn btn-primary install" data-href="<?php echo url('plugin-theme-'.$dir.'-1');?>" href="javascript:void(0);"><?php echo lang('install');?></a>
                    <?php } ?>

                    <?php if($plugin['installed'] && $plugin['type'] == 1) { ?>
                    <a role="button" class="btn btn-danger uninstall" data-href="<?php echo url('plugin-theme-'.$dir.'-0');?>" href="javascript:void(0);"><?php echo lang('uninstall');?></a>
                    <?php } ?>

					<?php if($plugin['have_upgrade']) { ?>
					<a role="button" class="btn btn-primary upgrade" href="<?php echo url("plugin-upgrade-$dir"); ?>"><?php echo lang('update');?></a>
					<?php } ?>

				</p>
		</div>

			<p class="mt-3 text-center">
                <a role="button" class="btn btn-secondary btn-block col-md-3 mx-auto mt-3" href="javascript:history.back();"><?php echo lang('back');?></a>
            </p>
		</div>
    </div>
</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>
<script src="<?php echo admin_view_path();?>js/jquery.qrcode.min.js"></script>
<script>
    var jform = $('#form');
    jform.on('submit', function() {
        jform.reset();
        var jthis = $(this);
        var jsubmit = jthis.find('#submit');
        jsubmit.button('loading');
        var postdata = jform.serializeObject();
        $.xpost(jform.attr('action'), postdata, function(code, message) {
            if(code == 0) {
                jsubmit.button(message).delay(1000).location();
            } else if(xn.is_number(code)) {
                $.alert(message);
                jsubmit.button('reset');
            } else {
                jform.find('[name="'+code+'"]').alert(message).focus();
                jsubmit.button('reset');
            }
        });
        return false;
    });

<?php if(!empty($plugin['storeid']) && !empty($url) && !is_dir(APP_PATH."plugin/$dir")) { ?>

	/*定时查询，如果支付成功，则跳转到下载*/
	var dir = '<?php echo $dir;?>';
	var url = "<?php echo $url;?>";
	 $('#qrcode').qrcode({
		render: "canvas", /*设置渲染方式，有table和canvas，使用canvas方式渲染性能相对来说比较好*/
		text: url, /*扫描二维码后显示的内容,可以直接填一个网址，扫描二维码后自动跳向该链接*/
		width: 200, /*二维码的宽度*/
		height: 200,
		background: "#ffffff", /*二维码的后景色*/
		foreground: "#000000", /*二维码的前景色*/
		src: "",
		imgWidth: 50,
		imgHeight: 50
	});

	var t = setInterval(function() {
		$.xget(xn.url('plugin-is_bought-'+dir), function(code, message) {
			if(code == 0) {
				/*支付成功，跳转到下载*/
				clearInterval(t);
				window.location = xn.url('plugin-download-'+dir);
			}
		});
	}, 5000);
<?php } ?>

    $('#nav li.nav-item-plugin').addClass('active');
    $('#plugin').addClass('show');
    $('.sidebar-sticky li.menu-plugin').addClass('active').prepend('<div class="arrow-tips float-right d-none d-md-block"></div>');
</script>